package com.example.auth.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.auth.domain.SysRole;
import com.example.auth.mapper.SysRoleMapper;
import com.example.auth.service.SysRoleService;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
* @author CETC
* @description 针对表【sys_role】的数据库操作Service实现
* @createDate 2025-11-01 12:18:37
*/
@Service
public class SysRoleServiceImpl extends ServiceImpl<SysRoleMapper, SysRole>
    implements SysRoleService {

    private static String[] ROLE_GROUP={"vip","account","super_vip","system","security"};

    @Override
    public SysRole saveSysRole(SysRole sysRole) {
        this.baseMapper.insert(sysRole);
        return sysRole;
    }

    @Override
    public SysRole getSysRoleById(String uuid) {
        return this.baseMapper.selectById(uuid);
    }

    @Override
    public SysRole getSysRoleByRoleNo(String roleNo) {
        LambdaQueryWrapper<SysRole> lambdaQueryWrapper=new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(SysRole::getRoleNo, roleNo);
        SysRole sysRole=this.baseMapper.selectOne(lambdaQueryWrapper);
        return sysRole;
    }

    @Override
    public boolean deleteSysRoleById(String uuid) {
        SysRole sysRole=this.getSysRoleById(uuid);
        if(sysRole==null){
            return false;
        }
        List<String> strings= Arrays.asList(ROLE_GROUP);
        if(strings.contains(sysRole.getRoleNo())){
            return false;
        }
        int num=this.baseMapper.deleteById(uuid);
        return num>0;
    }
}




